package rpc.loadbalance;

import rpc.remote.dto.RpcRequest;

import java.util.List;

/**
 * @ClassName: AbstractLoadBalance
 * @Description:
 * @author: Kowk
 * @since:1.0.0
 */
public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceAddresses, RpcRequest request) {
        if (serviceAddresses == null || serviceAddresses.size() == 0) {
            return null;
        }
        if(serviceAddresses.size() == 1){
            return serviceAddresses.get(0);
        }
        return doSelect(serviceAddresses,request);
    }

    protected abstract String doSelect(List<String> serviceAddresses, RpcRequest request);
}
